﻿using System;

namespace K.Client
{
    /// <summary>
    /// 单例类基类  
    /// </summary>
    public class Singleton<T> where T : class, new()
    {
        private static T mInstance;

        static Singleton()
        {
            mInstance = new T();
        }

        public static T Instance
        {
            get { return CreateInstance(); }
        }

        public static T CreateInstance()
        {
            if (mInstance == null)
            {
                mInstance = Activator.CreateInstance<T>();
            }
            return mInstance;
        }

        public static void DestroyInstance()
        {
            if (mInstance != null)
            {
                mInstance = null;
            }
        }
    }
}